package org.ne.springboot.exception;


import jakarta.servlet.http.HttpServletResponse;
import lombok.extern.slf4j.Slf4j;
import org.ne.springboot.pojo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

//    @ExceptionHandler(value = Exception.class)
//    public Result handleException(Exception e) {
//        e.printStackTrace();
//        return Result.error(!e.getMessage().isEmpty() ? e.getMessage() : "操作失败！");
//    }


    public static final String CLIENT_ABORT_EXCEPTION_CLASS = "org.apache.catalina.connector.ClientAbortException";

    @ExceptionHandler(Exception.class)
    public void handleException(Exception e, HttpServletResponse response) {
        if (CLIENT_ABORT_EXCEPTION_CLASS.equals(e.getClass().getName())) {
            log.warn("出现ClientAbortException");
            return;
        };
        log.error("全局异常信息：{}", e.getMessage(), e);
    }
}
